#include "mychart.h"
#include <QDebug>

MyChart::MyChart(QObject *parent)
    : QObject{parent}
{
    this->init();
}

MyChart::~MyChart()
{
    delete graph;
    delete charts;
    delete chartView;
}

void MyChart::init()
{
    graph = new QLineSeries();
    charts = new chart();
    charts->addSeries(graph);

    graph->append(QPointF(400.0, 15.0));
    graph->append(QPointF(500.0, 15.0));
    graph->append(QPointF(600.0, 20.0));
    graph->append(QPointF(6000.0, 5.0));

    charts->legend()->hide();
    charts->createDefaultAxes();
    charts->axisX()->setRange(400.0, 6000.0);
    charts->axisY()->setRange(0.0, 20.0);


    chartView = new ChartView(charts);
    chartView->setRenderHint(QPainter::Antialiasing);

    // charts->axisX(graph)->setRange(400.0, 6000.0);
    // chartView->chart()->setAxisX(charts->axisX(graph), graph);

    // charts->axisY()->setRange(0.0, 20.0);
    // chartView->chart()->setAxisY(charts->axisY(graph), graph);
    qDebug() << graph->at(0) << graph->at(1) << graph->at(2);
}

void MyChart::setNewDataSerie(QList<QPointF> newData)
{
    graph->replace(newData);
    // charts->removeSeries(graph);
    // charts->addSeries(graph);
    qDebug() << graph->at(0) << graph->at(1) << graph->at(2);
}
